package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.domain.Attendance;
import org.ahuanlien.crm.query.StaffManagementQueryObject;
import org.ahuanlien.crm.service.IAttendanceService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("attendance")
public class AttendanceController {

    @Autowired
    IAttendanceService attendanceService;

    @RequestMapping("view")
    public String view() {
        return "attendance/view";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(StaffManagementQueryObject qo) {
        PageResult result = attendanceService.query(qo);
        return result;
    }

    @RequestMapping("save")
    @ResponseBody
    public JSONResult save() {
        try {
            attendanceService.save();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult("签到成功", false);
        }
        return new JSONResult();

    }


    @RequestMapping("sign")
    @ResponseBody
    public JSONResult sign() {
        try {
            attendanceService.outCard();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult("签退成功", false);
        }
        return new JSONResult();


    }
}
